package com.wizz.trade.util;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;


import java.util.*;

/**
 * @author fyftless
 */
public class CodeGenerator {

    public static void main(String[] args) {

        List<String> excludeTable = new ArrayList<>();
        excludeTable.add("sys_role_menu");
        excludeTable.add("sys_user_role");

        String url = "jdbc:mysql://175.24.206.192:55107/spot-trade?characterEncoding=UTF-8&useUnicode=true&useSSL=false";
        FastAutoGenerator
                .create(url, "root","f9K2ABV6zLk0qM7jdgB3mBSt")
                .globalConfig(builder -> {
                    builder.author("fyftless")
                            .commentDate("yyyy-MM-dd hh:mm:ss")
                            .outputDir(System.getProperty("user.dir")+"/src/main/java")
                            .disableOpenDir();
                })
                .packageConfig(builder -> {
                    builder.parent("com.wizz.trade.trading")
                            .entity("entity")
                            .mapper("mapper")
                            .service("service")
                            .serviceImpl("service.impl")
                            .pathInfo(Collections.singletonMap(OutputFile.xml, System.getProperty("user.dir")
                            + "/src/main/resources/mappers"));
                })
                .strategyConfig(builder -> {
                    builder
//                            .addExclude(excludeTable) // 设置需要排除的表
                            .addInclude("fposition")
                            // Entity 策略配置
                            .entityBuilder()
                            .enableLombok() //开启 Lombok
//                            .enableFileOverride() // 覆盖已生成文件
                            .enableTableFieldAnnotation()  //开启字段注释
//                            .addTableFills(new Column("create_time", FieldFill.INSERT))
//                            .addTableFills(new Property("updateTime", FieldFill.INSERT_UPDATE))
                            .naming(NamingStrategy.underline_to_camel)  //数据库表映射到实体的命名策略：下划线转驼峰命
                            .columnNaming(NamingStrategy.underline_to_camel)    //数据库表字段映射到实体的命名策略：下划线转驼峰命
                            // Mapper 策略配置
                            .mapperBuilder()
//                            .enableFileOverride() // 覆盖已生成文件
                            .formatMapperFileName("%sMapper")
                            .formatXmlFileName("%sMapper")
                            // Service 策略配置
                            .serviceBuilder()
//                            .enableFileOverride() // 覆盖已生成文件
                            .formatServiceFileName("%sService") //格式化 service 接口文件名称，%s进行匹配表名，如 UserService
                            .formatServiceImplFileName("%sServiceImpl") //格式化 service 实现类文件名称，%s进行匹配表名，如 UserServiceImpl
                            // Controller 策略配置
                            .controllerBuilder()
//                            .enableFileOverride() // 覆盖已生成文件
                            .formatFileName("%sController")
                            .enableRestStyle();
                })
                .execute();
    }
}
